package com.aaa.controller;

import com.aaa.common.domain.UserInfo;
import com.aaa.common.query.UserInfoQuery;
import com.aaa.common.result.Result;
import com.aaa.service.impl.UserInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/ui")
public class UserInfoController {

    @Autowired
    private UserInfoServiceImpl service;

    /**
     * 查询用户
     */
    @PostMapping("/listP")
    public Result listPersonRenter(@RequestBody UserInfoQuery userInfoQuery){
        Result result = service.listUser(userInfoQuery);
        System.out.println(result);
        return result;
    }

    /**
     * 添加用户
     * @return
     */
    @PostMapping("/add")
    public Result addPersonRenter(@RequestBody Map<String,Object> datas){
        Result result = service.addUser(datas);
        return result;
    }

    /**
     * 通过id查询用户信息表和角色表数据
     * @param id
     * @return
     */
    @GetMapping("/getId")
    public Result getUserInfoById(Integer id){
        return service.queryUFById(id);
    }



    /**
     * 修改用户
     * @return
     */
    @PostMapping("/update")
    public Result updatePersonRenter(@RequestBody UserInfo userInfo){
        boolean b = service.updateUser(userInfo);
        if (b==true){
            return Result.success(b);
        }
        return Result.error("error");
    }

    /**
     * 删除用户
     * @return
     */
    @DeleteMapping("/delete")
    public Result delPersonRenter(String ids){
        Result result = service.deleteUser(ids);
        return result;
    }
}
